<?php
class PlanController extends BaseController {
	public function _initialize() {
		parent::_initialize();
		// $this->db = model('User');
    }

    public function plan()
    {   
        
        $set_time = C('site_hour');
        $mtime= date("Y-m-d H:i:s", strtotime("-$set_time hour"));
        $buy_list = M('hang_buy')->where(['status'=>2,'update_time'=>['lt',$mtime]])->select();
        foreach($buy_list as $key =>$value){
            //超时未支付
            //C('site_trade_percent')
            $bili = C('site_trade_percent');
            
            M('hang_buy')->where(['id'=>$value['id']])->setField('status',5);
            $user_info = M('user')->where(['id'=>$value['sell_id']])->field('id,upvaluation,freeze_upvaluation')->find();
            $upvaluation = (1+$bili/100)*$value['all_price'];
            $data = [
                'upvaluation'=>$user_info['upvaluation'] + $upvaluation,
                'freeze_upvaluation' => $user_info['freeze_upvaluation'] - $upvaluation,
                
            ];
            M('user')->where(['id'=>$value['sell_id']])->save($data);
            $data1 = [
                'user_id'=>$value['sell_id'],
                'balance'=>$upvaluation,
                'type'=>2,
                'add_time'=>date('Y-m-d H:i:s'),
                'remarks'=>'买家未及时付款返还'.$upvaluation.'GF',
            ];
            M('upvaluation_exchange_records')->add($data1);
            M('user')->where(['id'=>$value['user_id']])->setField('status',2);
        }


        // $buy_list1 = M('hang_buy')->where(['status'=>3,'update_time'=>['lt',$mtime]])->select();
        // foreach($buy_list1 as $key =>$value){
        //     //超时未支付
        //     //C('site_trade_percent')
        //     $bili = C('site_trade_percent');
            
        //     M('hang_buy')->where(['id'=>$value['id']])->setFile('status',5);
        //     $user_info = M('user')->where(['id'=>$value['sell_id']])->field('id,upvaluation,freeze_upvaluation')->find();
        //     $upvaluation = (1+$bili/100)*$value['all_price'];
        //     $data = [
        //         'upvaluation'=>$user_info['upvaluation'] + $upvaluation,
        //         'freeze_upvaluation' => $user_info['freeze_upvaluation'] - $upvaluation
        //     ];
        //     M('user')->where(['id'=>$value['sell_id']])->save($data);
        //     $data1 = [
        //         'user_id'=>$value['sell_id'],
        //         'balance'=>$upvaluation,
        //         'type'=>2,
        //         'add_time'=>date('Y-m-d H:i:s'),
        //         'remarks'=>'买家未及时付款返还'.$upvaluation.'GF',
        //     ];
        //     M('upvaluation_exchange_records')->add($data1);
        // }
        


        
    }
}